package com.dayuanit.dy15.atm.task;

import com.dayuanit.dy15.atm.entity.TransferOrder;
import com.dayuanit.dy15.atm.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 处理转账订单退款的
 */
@Component
public class TransferBackTask extends BaseTask {

    @Autowired
    @Qualifier("cardServiceTransferImpl")
    private CardService cardService;


    @Override
    @Scheduled(cron=" */20  *  *  *  *  ?")
    public void process() {
        processTraansferBack();
    }

    /**
     * 处理退款业务定时器
     */
    private void processTraansferBack() {
        List<TransferOrder> transferOrders = cardService.listTransferOrder4Back();
        for (TransferOrder order : transferOrders) {
            try {
                cardService.processTransferBack(order);
                System.out.println(">>>>>订单" + order.getId() + "退款成功");
            } catch (Exception e) {
                e.printStackTrace();
                //TODO 当系统无法处理的时候，可以人工介入，走线下处理。(形成闭环)
            }
        }
    }
}
